package com.application.tourapp;

import java.util.ArrayList;

import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

import com.application.tourapp.async.TypesAsyncActivity;
import com.application.tourapp.baseadapter.TypeListBaseAdapter;
import com.application.tourapp.dal.TypeDAL;
import com.application.tourapp.model.Type;

public class TypesActivity extends GenericActivity {
	/** Called when the activity is first created. */
	public ListView listTypes;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.types_activity);
        setHeader(getResources().getString(R.string.Types), true, true);
        Context context = getApplicationContext();
        new TypesAsyncActivity(this).execute();
        ArrayList<Type> typeDetails = GetSearchResults(context);
        
        listTypes = (ListView) findViewById(R.id.listV_main);
        listTypes.setAdapter(new TypeListBaseAdapter(this, typeDetails));
        listTypes.setOnItemClickListener(new OnItemClickListener() {
        	@Override
        	public void onItemClick(AdapterView<?> a, View v, int position, long id) { 
        		Object o = listTypes.getItemAtPosition(position);
            	Type objType = (Type)o;
            	System.out.println("The type name = " + objType.getName());
        		//Toast.makeText(TypesActivity.this, "You have chosen : " + " " + obj_Item.getName(), Toast.LENGTH_LONG).show();
            	//Starting a new Intent
                Intent touristicItemsScreenIntent = new Intent(getApplicationContext(), TouristicItemsActivity.class);
                ItemsGroupActivity parentActivity = (ItemsGroupActivity)getParent();
                touristicItemsScreenIntent.putExtra("id_type", Integer.toString(objType.getId()));
         		parentActivity.startChildActivity("TouristicItemsActivity", touristicItemsScreenIntent);
                //Sending data to another Activity
                /*itemsScreen.putExtra("name", "alo");
                Log.e("n", "ALO");*/
                
        	}  
        });
    }
    
    public ArrayList<Type> GetSearchResults(Context context) {
    	return new TypeDAL(context).getAlltypes();
    }
}